import React from 'react';
import {
  Form,
  Modal,
  Card,
  Button,
  Input
} from 'antd';
import DescriptionList from 'components/DescriptionList';
import styles from './index.less';
import { productType, checkAmount, quoteType } from "utils/enumConfig"
import { LwjDownload } from 'components';

const { Description } = DescriptionList;
const FormItem = Form.Item
const { TextArea } = Input;
const confirmQuoteModal = ({
  currentContractDetail,
  acceptQuote,
  denyQuote,
  isAcceptLoading,
  isDenyLoading,
  dispatch,
  form: {
    getFieldDecorator,
    validateFieldsAndScroll
  },
  ...confirmQuoteModalProps
}) => {

  const handleSubmit = (auditType) => {
    validateFieldsAndScroll((err, values) => {
      if (!err) {
        if (auditType === "AGREE") {
          if (currentContractDetail.orderQuoteSummary.deductionType === "COUPONS") {
            dispatch({
              type: 'updateContractOrder/acceptQuote',
              payload: {}
            })
          } else {
            acceptQuote(values);
          }
        } else {
          if (_.isEmpty(values.quoteDeniedReason)) {
            Modal.info({ title: '提示', content: `请填写审核备注` });
            return;
          }
          values.version = currentContractDetail.version;
          denyQuote(values);
        }
      }
    });
  };

  return (
    <Modal {...confirmQuoteModalProps}>
      {(!_.isEmpty(currentContractDetail) && currentContractDetail.status === "PENDING_CONFIRM_QUOTED") && <Card bordered={false}>
        <DescriptionList
          title="报价信息"
          size="small"
          style={{ marginBottom: 32 }}>
          <Description term="合同号">{currentContractDetail.contractNum}</Description>
          <Description term="产品类型">{productType[currentContractDetail.productType]}</Description>
          <Description term="原订单金额">{checkAmount(currentContractDetail.orderQuoteSummary.preOrderAmount)}</Description>
          <Description term="装修返点金额">{checkAmount(currentContractDetail.orderQuoteSummary.decorationRebateAmount)}</Description>
          <Description term="样柜返点金额">{checkAmount(currentContractDetail.orderQuoteSummary.cabinetRebateAmount)}</Description>
          <Description term="活动优惠金额">{checkAmount(currentContractDetail.orderQuoteSummary.eventsAmount)}</Description>
          <Description term="订单金额">{checkAmount(currentContractDetail.orderQuoteSummary.orderAmount)}</Description>
          <Description term="报价方案">{<LwjDownload title={'点击下载'} targetUrl={currentContractDetail.orderQuoteSummary.quoteAttachment} />}</Description>
        </DescriptionList>
        <DescriptionList
          title="支付方式"
          size="small"
          style={{ marginBottom: 32 }}>
          <Description term={quoteType[currentContractDetail.orderQuoteSummary.deductionType]}>{currentContractDetail.orderQuoteSummary.orderAmount}</Description>
        </DescriptionList>
        <div className={styles.title}>备注</div>
        <Form layout="horizontal">
          <FormItem>
            {getFieldDecorator('quoteDeniedReason')(
              <TextArea
                style={{ minHeight: 32 }}
                placeholder="请输入备注"
                rows={4} />)}
          </FormItem>
          <FormItem
            wrapperCol={{ span: 6, offset: 19 }}>
            <Button type="primary" onClick={() => handleSubmit("AGREE")} style={{ marginRight: 10 }} loading={isAcceptLoading}>
              报价通过
            </Button>
            <Button type="primary" onClick={() => handleSubmit("DISAGREE")} loading={isDenyLoading}>
              报价不通过
            </Button>
          </FormItem>
        </Form>
      </Card>}
    </Modal>
  )
}

export default Form.create()(confirmQuoteModal);
